package com.spring.lesson001.demo5;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author vhans
 */
public class DiTest {

    @Test
    public void diByConstructorParamIndex() {
        String beanXml = "diByConstructorParam0015.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        System.out.println(context.getBean("diByConstructorParamIndex"));
    }

    @Test
    public void diByConstructorParamType() {
        String beanXml = "diByConstructorParam0015.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        System.out.println(context.getBean("diByConstructorParamType"));
    }

    @Test
    public void diByConstructorParamName() {
        String beanXml = "diByConstructorParam0015.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        System.out.println(context.getBean("diByConstructorParamName"));
    }

    @Test
    public void diBySetter() {
        String beanXml = "diBySetter0015.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        System.out.println(context.getBean("diBySetter"));
    }

    @Test
    public void diByBean() {
        String beanXml = "diByBean0015.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        for (String beanName : context.getBeanDefinitionNames()) {
            System.out.println(beanName + ":" + context.getBean(beanName));
        }
    }

    @Test
    public void diByOtherType() {
        String beanXml = "diByOtherType0015.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        System.out.println(context.getBean("diByOther"));
    }
}
